package com.et114.core.control;

//import org.springframework.beans.factory.InitializingBean;
import org.apache.struts.util.TokenProcessor;
import org.apache.struts.Globals;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author V1
 */
public class TokenMapClient  {
	
	/**
	 * @return Returns the tokenMap.
	 */
	public ITokenMap getTokenMap ( ) {
		return ActionFactoryBean.tokenMap ;
	}
	
	
	public synchronized static String generateToken ( HttpServletRequest request ) {
		HttpSession session = request.getSession ( );
		return TokenProcessor.getInstance ( ).generateToken ( session.getId ( ) );
	}
	
	
	public synchronized static void saveToken ( HttpServletRequest request ) {
		HttpSession session = request.getSession ( );
		String token = generateToken ( request );
		if ( token != null ) {
			session.setAttribute ( Globals.TRANSACTION_TOKEN_KEY , token );
		}
	}

}
